package com.cykj.service.impl;

import com.cykj.mapper.MockMapper;
import com.cykj.service.MockService;
import com.cykj.vo.ChatRecordVO;
import com.cykj.vo.MockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.service.impl
 * @Author: 张昌煜
 * @CreateTime: 2025-08-27 15:41
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class MockServiceImpl implements MockService {
    @Autowired
    private MockMapper mockMapper;
    @Override
    public Integer insertMock(String sessionId, Integer userId,String s) {
        MockVO mockVO = new MockVO();
        mockVO.setSessionId(sessionId);
        mockVO.setUserId(userId);
        Integer i = mockMapper.insertMock(mockVO);
        if (i > 0) {
            ChatRecordVO chatRecordVO = new ChatRecordVO();
            chatRecordVO.setChatInfo(s);
            chatRecordVO.setMockId(mockVO.getMockId());
            chatRecordVO.setSendId(0);
            chatRecordVO.setSendRole("ai");
            chatRecordVO.setReceiveRole("user");
            chatRecordVO.setReceiveId(userId);
            i = mockMapper.insertChat(chatRecordVO);
            if (i > 0) {
                return mockVO.getMockId();
            }else{
                return 0;
            }
        }
        return 0;
    }

    @Override
    public Integer insertUserChat(String sessionId, Integer userId, String answer, Integer mockId) {
        ChatRecordVO chatRecordVO = new ChatRecordVO();
        chatRecordVO.setChatInfo(answer);
        chatRecordVO.setMockId(mockId);
        chatRecordVO.setReceiveId(0);
        chatRecordVO.setReceiveRole("ai");
        chatRecordVO.setSendRole("user");
        chatRecordVO.setSendId(userId);
        Integer i = mockMapper.insertChat(chatRecordVO);
        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public Integer insertAiChat(String sessionId, Integer userId, String nextQuestion, Integer mockId) {
        ChatRecordVO chatRecordVO = new ChatRecordVO();
        chatRecordVO.setChatInfo(nextQuestion);
        chatRecordVO.setMockId(mockId);
        chatRecordVO.setSendId(0);
        chatRecordVO.setSendRole("ai");
        chatRecordVO.setReceiveRole("user");
        chatRecordVO.setReceiveId(userId);
        Integer i = mockMapper.insertChat(chatRecordVO);
        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public Integer updateMock(String overallFeedback, Integer mockId) {
        Integer i = mockMapper.updateMock(overallFeedback,mockId);
        return 0;
    }
}
